﻿using System.Data;
using BusinessLogic.BusinessRules;
using DataAccess;
using Model.Data;

namespace BusinessLogic.ClassFactory
{
    /// <summary>
    /// ArtSecRelationFactory 的摘要说明。
    /// </summary>
    public class ArtSecRelationFactory : BaseFactory
    {
        public ArtSecRelationFactory()
            : base()
        {
            //
            // TODO: 在此处添加构造函数逻辑
            //
        }

        public ArtSecRelationFactory(DBManager l_DBManager)
            : base(l_DBManager)
        {
        }

        public ArtSecRelation NewInstance()
        {
            ArtSecRelationAccess l_Access = new ArtSecRelationAccess(m_Manager);
            ArtSecRelation objArtSecRelation = new ArtSecRelation(this.m_Manager, l_Access);
            objArtSecRelation.NewDataSet();
            objArtSecRelation.SelectRow(0);
            return objArtSecRelation;
        }

        public ArtSecRelation CreatorBySql(string Sql)
        {
            ArtSecRelationAccess l_Access = new ArtSecRelationAccess(m_Manager);
            ArtSecRelation objArtSecRelation = new ArtSecRelation(this.m_Manager, l_Access);
            DataSet l_ds = new ArtSecRelationData();
            if (l_Access.QueryBySql(ref l_ds, Sql) < 1)
            {
                return null;
            }
            objArtSecRelation.SetDataSet(l_ds);
            objArtSecRelation.SelectRow(0);
            return objArtSecRelation;
        }

        public ArtSecRelation CreatorByFullSql(string Sql)
        {
            ArtSecRelationAccess l_Access = new ArtSecRelationAccess(m_Manager);
            ArtSecRelation objArtSecRelation = new ArtSecRelation(this.m_Manager, l_Access);
            DataSet l_ds = new ArtSecRelationData();
            if (l_Access.QueryByQuerySql(ref l_ds, Sql) < 1)
            {
                return null;
            }
            objArtSecRelation.SetDataSet(l_ds);
            objArtSecRelation.SelectRow(0);
            return objArtSecRelation;
        }

        public int UpdateRemove(string strArticleIDs, string strSectionID)
        {
            ArtSecRelationAccess l_Access = new ArtSecRelationAccess(m_Manager);
            return l_Access.UpdateSectionID(strArticleIDs, strSectionID);
        }

        /// <summary>
        ///
        /// </summary>
        /// <param name="intSecArtID"></param>
        /// <returns></returns>
        public ArtSecRelation Creator(int intSecArtID)
        {
            ArtSecRelationAccess l_Access = new ArtSecRelationAccess(m_Manager);
            ArtSecRelation objArtSecRelation = new ArtSecRelation(this.m_Manager, l_Access);
            DataSet l_ds = new ArtSecRelationData();
            if (l_Access.QueryByID(ref l_ds, intSecArtID) < 1)
            {
                return null;
            }
            objArtSecRelation.SetDataSet(l_ds);
            objArtSecRelation.SelectRow(0);
            return objArtSecRelation;
        }

        public ArtSecRelation Creator()
        {
            ArtSecRelationAccess l_Access = new ArtSecRelationAccess(m_Manager);
            ArtSecRelation objArtSecRelation = new ArtSecRelation(this.m_Manager, l_Access);
            DataSet l_ds = new ArtSecRelationData();
            if (l_Access.QueryAll(ref l_ds) < 1)
            {
                return null;
            }
            objArtSecRelation.SetDataSet(l_ds);
            objArtSecRelation.SelectRow(0);
            return objArtSecRelation;
        }

        public int Delete(int intArticleID)
        {
            ArtSecRelationAccess l_Access = new ArtSecRelationAccess(m_Manager);
            return l_Access.Delete(intArticleID);
        }

        public int DeleteWhere(string where)
        {
            ArtSecRelationAccess l_Access = new ArtSecRelationAccess(m_Manager);
            return l_Access.DeleteWhere(where);
        }

        public int QueryByCompletionSql(string Sql)
        {
            ArtSecRelationAccess l_Access = new ArtSecRelationAccess(m_Manager);
            ArtSecRelation objArtSecRelation = new ArtSecRelation(this.m_Manager, l_Access);
            DataSet l_ds = new ArtSecRelationData();
            if (l_Access.QueryByQuerySql(ref l_ds, Sql) < 1)
            {
                return 0;
            }
            objArtSecRelation.SetDataSet(l_ds);
            objArtSecRelation.SelectRow(0);
            return objArtSecRelation.Data.ArtSecRelation.Rows.Count;
        }
    }
}